<?php
function parse_ret($line)
{
    $name =  strtok($line, '?');
    $url = strtok('?');
    /*$others = $strtok('?'); 

    $size = strtok($others, '&');
    $time = strtok('&');
    $type = strtok('&');*/

    $begin = strpos($url, '@', 0);
    $begin2 = strpos($url, '/', $begin) + 1;
    $r_url = substr($url, $begin2, strlen($url) - $begin2);

    print '<font color=blue>' . $name . '</font><br />';
    print '&nbsp &nbsp <font color=black>' . $r_url . '</font><br />';
}

if(isset($_POST['send'])  && ($_POST['send'])){
    if(!$fp=fsockopen('10.0.1.198', 9093, $errstr, $errno, 30)){
	trigger_error('Error opening socket', E_USER_ERROR);
    }

    $message = $_POST['message'];
    fputs($fp, $message);
    $ret = fgets($fp, 1024);

    echo '<html>';
    echo '<head><title>Search Results</title></head>';
    echo '<body>';
    echo '<font color=blue>' . $ret . ' </font> results for query: <font color=blue>' . $message .'</font> <br />';
    echo '<hr />';
    echo '<div>';
    while(!feof($fp))
    {
	$ret = fgets($fp, 1024);

	parse_ret($ret);
	//echo $ret . '<br />';
    }
    echo '</div>';
    echo '</body></html>';

    fclose($fp);
    exit();
}
?>

<html>
<head>
<title>Query </title>
<meta http-equiv="Content-Type" content="text/html; charset=utf8" />
</head>

<body>
<div align=center>
<h3>Enter you Query</h3>
<form aciton="<?php echo $_SERVER['PHP_SELF'] ?>" method = "POST">
<input type="text" name="message" size="30" /><br />
<input type="submit" name="send" value="Search" />
</form>
</div>
</body>
</html>
